﻿<%@ Page Title="" Language="C#" MasterPageFile="~/QuanLyDuoc/HeThongTaiChinh/ThanhToanHoaDon/Master_ThanhToanHoaDon.master" AutoEventWireup="true" CodeBehind="ThanhToanPhieuXuatKhac.aspx.cs" Inherits="HospitalManager.QuanLyDuoc.HeThongTaiChinh.ThanhToanHoaDon.ThanhToanPhieuXuatKhac" %>

<%@ Register Src="~/QuanLyDuoc/HeThongNhapXuat/PhieuXuatKhac/uc_ViewPhieu.ascx" TagName="uc_ViewPhieu" TagPrefix="uc2" %>
<asp:Content ID="Content3" ContentPlaceHolderID="TopContent_ThanhToanHoaDon" runat="server">
    <h1 style="font-size: 30px; margin: 0;">
        <small class="breadcrumb" style="background-color: #ffffff; font-size: 50%; padding: 0 20px;">
            <li><a href="/QuanLyDuoc/HeThongTaiChinh/HeThongTaiChinh.aspx">HỆ THỐNG TÀI CHÍNH</a></li>
            <li class="active">THANH TOÁN HÓA ĐƠN</li>
            <li class="active">Hóa đơn phiếu xuất khác</li>
        </small>
    </h1>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent_ThanhToanHoaDon" runat="server">
    <div class="row">
        <div class="form-horizontal">
            <div class="col-xs-4 col-md-4">
                <asp:DropDownList ID="ddlKho_Khoa" runat="server" ClientIDMode="Static">
                </asp:DropDownList>
            </div>
            <div class="col-xs-6 col-md-6">
                <div class="input-group">
                    <span class="input-group-addon">Từ ngày</span>
                    <asp:TextBox ID="txtTuNgay" ClientIDMode="Static" runat="server" CssClass="form-control ipdate dateFormat"
                        placeholder="Từ ngày"></asp:TextBox>
                    <span class="input-group-addon" style="border-right: 0;">đến ngày</span>
                    <asp:TextBox ID="txtDenNgay" ClientIDMode="Static" runat="server" CssClass="form-control ipdate dateFormat"
                        placeholder="Đến ngày"></asp:TextBox>
                </div>
            </div>
            <div class="col-xs-2 col-md-2">
                <asp:Button ID="btnTimKiem" ClientIDMode="Static" runat="server" Text="Tìm kiếm" CssClass="btn btn-default"
                    OnClientClick="validationform_Timkiem()" OnClick="btnTimKiem_Click" />
            </div>
        </div>
    </div>
    <div class="row" style="margin-top: 10px;">
        <div class="col-md-12">
            <div class="form-group table-responsive">
                <asp:GridView ID="gvPhieuXuatKhac" runat="server" AutoGenerateColumns="False" Width="100%"
                    CssClass="table table-bordered table-condensed" DataKeyNames="MaPhieu" OnRowDataBound="gvPhieuXuatKhac_RowDataBound">
                    <Columns>
                        <asp:BoundField DataField="RowNumber" HeaderText="STT">
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="NgayGiao" HeaderText="Ngày xuất" DataFormatString="{0:dd-MM-yyyy}">
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="TenKho" HeaderText="Kho"></asp:BoundField>
                        <asp:BoundField DataField="NguoiGiao" HeaderText="Người xuất"></asp:BoundField>
                        <asp:BoundField DataField="NguoiNhan" HeaderText="Người nhận"></asp:BoundField>
                        <asp:BoundField DataField="TongThuoc" HeaderText="Tổng thuốc" DataFormatString="{0:n0}">
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="TongTien" HeaderText="Tổng tiền" DataFormatString="{0:n0}">
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnViewPhieuXuatKhac" runat="server" ToolTip="Xem thông tin phiếu"
                                    CssClass="btn btn-success" maphieu='<%# Eval("MaPhieu") %>' OnClientClick="viewphieuxuatkhac(this);" href="javascript:void(0)">
                                    <i class="glyphicon glyphicon-search"></i>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnDuyetPhieuXuatKhac" runat="server" ToolTip="Duyệt phiếu"
                                    CssClass="btn btn-info" CommandArgument='<%# Eval("MaPhieu") %>' maphieu='<%# Eval("MaPhieu") %>'
                                    OnClientClick="return CheckVatTuDu(this.id);" OnClick="btnDuyetPhieuXuatKhac_Click">
                                    <i class="glyphicon glyphicon-check"></i>
                                </asp:LinkButton>
                                <div class="btn-group dropup" id="dd-TraPhieuXuatKhac">
                                    <asp:LinkButton ID="btnDropDownTraLaiPhieuXuatKhac" runat="server" ToolTip="Trả lại phiếu"
                                        CssClass="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false" OnClientClick="$('.dropdown-menu-form').find('input:text').val('');">
                                        <i class="glyphicon glyphicon-share"></i>
                                    </asp:LinkButton>
                                    <ul class="dropdown-menu dropdown-menu-right dropdown-menu-form" role="menu" style="width: 460px;">
                                        <li>
                                            <div class="col-xs-12 col-md-12" style="margin-top: 10px;">
                                                <div class="form-horizontal">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">
                                                            Lý do</label>
                                                        <div class="col-sm-10">
                                                            <asp:TextBox ID="txtGhiChu" runat="server" CssClass="form-control"></asp:TextBox>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="col-xs-12 col-md-12">
                                                <div class="form-horizontal">
                                                    <div class="form-group">
                                                        <div class="col-sm-offset-2 col-sm-10">
                                                            <asp:LinkButton ID="btnTraLaiPhieuXuatKhac" runat="server" Text="Chấp nhận"
                                                                CssClass="btn btn-success" CommandArgument='<%# Eval("MaPhieu") %>'
                                                                OnClick="btnTraLaiPhieuXuatKhac_Click">
                                                            </asp:LinkButton>
                                                            <asp:LinkButton ID="btnThoat" runat="server" Text="Thoát" CssClass="btn btn-danger"
                                                                OnClientClick="$('.dropdown-menu-form').parent().removeClass('open');" href="javascript:void(0)"></asp:LinkButton>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="15%" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
        </div>
        <div class="col-md-6" style="text-align: right;">
            <asp:DataList RepeatDirection="Horizontal" runat="server" ID="dlPager" OnItemCommand="dlPager_ItemCommand"
                CssClass="tbPage">
                <ItemTemplate>
                    <asp:LinkButton Enabled='<%#Eval("Enabled") %>' runat="server" ID="lnkPageNo" Text='<%#Eval("Text") %>'
                        CommandArgument='<%#Eval("Value") %>' CommandName="PageNo"></asp:LinkButton>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </div>
    <asp:HiddenField ID="hfPageIndex" runat="server" Value="1" />
    <asp:HiddenField ID="hfStatusPhieu" runat="server" Value="0" />
    <asp:HiddenField ID="hfStrTraPhieu" runat="server" Value="" />
    <script type="text/javascript">
        $(function () {
            $(".dropdown-menu-form").on("click", function (e) {
                $(this).find("input:text:first").focus();
                e.stopPropagation();
            });
        });
        var confirmed = false;
        function CheckVatTuDu(controlId) {
            if (confirmed) return true;
            var data = PhieuXuatKhac_ChiTiet_SelectByMaPhieu($("#" + controlId).attr("maphieu"));
            if (data.length <= 0) return false;
            var vattudu = true, tenvattu = "";
            for (var i = 0; i < data.length; i++) {
                if (parseInt(CheckTonThucTe_MaKho_MaVatTu($("#ddlKho_Khoa option:selected").val(), data[i].MaVatTu)) < parseInt(data[i].SoLuong)) {
                    vattudu = false;
                    tenvattu += (i == data.length - 1) ? "[" + data[i].TenVatTu + "]" : "[" + data[i].TenVatTu + "], ";
                }
            }
            if (vattudu) return true;
            bootbox.confirm("Vật tư " + tenvattu + " trong kho không còn đủ số lượng để xuất, trả lại phiếu yêu cầu xuất này?", function (result) {
                if (result) {
                    if (controlId != null) {
                        var controlToClick = document.getElementById(controlId);
                        if (controlToClick != null) {
                            confirmed = true;
                            $("#form_Main").validate().cancelSubmit = true;
                            $("#<%= hfStatusPhieu.ClientID%>").val("1");
                            $("#<%= hfStrTraPhieu.ClientID%>").val("Vật tư " + tenvattu + " trong kho không còn đủ số lượng để xuất");
                            controlToClick.click();
                            confirmed = false;
                        }
                    }
                }
            });
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FormContent_ThanhToanHoaDon" runat="server">
    <div id="div_phieuxuatkhac_view" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static"
        data-width="98%" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" style="line-height: 1;">
                        <span>&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">Phiếu xuất khác</h4>
                </div>
                <div class="modal-body modal-fullheight">
                    <uc2:uc_ViewPhieu ID="uc_ViewPhieu4" runat="server" />
                </div>
            </div>
        </div>
    </div>
</asp:Content>